//wifi类型的需求按钮的功能实现，与buttonWifi.vue绑定

import store from "@/store";
import axios from "axios";

function wifiPassword(){
    console.log("show wifi password");
    let roomNumber = store.getters.getRoomNumber;

    if(roomNumber!='default'){   
        store.dispatch('sendMessage', {       
            text: '正在获取本房间的wifi密码...', 
            receiver: true, 
            request:'default'},
        )
        //访问后端获取WiFi密码
        let url="http://localhost:8080/api/wifiPw";
        axios.get(url,{params:{roomNumber:roomNumber}})
            .then(result=>{
                store.dispatch('sendMessage', {       
                    text: result.data.message,
                    receiver: true, 
                    request:'default'},
                )     
            })
            .catch(err=>{
                console.log(err);
            })
    }else{
        store.dispatch('sendRequest', 'wifi密码');
        store.dispatch('sendMessage', {       
            text: '输入房间号', 
            receiver: true, 
            request:'房间号'},
        )   
    }
}

function wifiRepair(){
    let roomNumber = store.getters.getRoomNumber;
    if(roomNumber!='default'){   
        console.log("wifi repair request has been sent");
        store.dispatch('sendMessage', {       
            text: '已发送wifi报修的请求', 
            receiver: true, 
            request:'default'},
        )
    }else{
        store.dispatch('sendRequest', 'wifi报修');
        store.dispatch('sendMessage', {       
            text: '输入房间号', 
            receiver: true, 
            request:'房间号'},
        )   
    }
}

export default{wifiPassword, wifiRepair};

